<template>
  <el-dialog v-model="visible" title="通道选择策略" width="500px" @close="closeDialog">
    <el-form :model="form" label-width="120px">
      <el-form-item label="通道选择策略">
        <el-select v-model="form.channelSelectStrategy" placeholder="请选择策略">
          <el-option label="价格优先" value="price" />
          <el-option label="占比分流" value="rate" />
          <el-option label="优先级" value="priority" />
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="closeDialog">取消</el-button>
      <el-button type="primary" @click="submitForm">确定</el-button>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useMessage } from '/@/hooks/message';
import {getObj, putObj, updateConfig} from '/@/api/bms/customer/customer';

const visible = ref(false);
const form = ref({
  id: -1,
  channelSelectStrategy: ''
});


const openDialog = (customerId: number) => {
  getCustomer(customerId)

  visible.value = true;
};


const getCustomer = (customerId)=> {
  getObj(customerId).then((res: any) => {
    Object.assign(form.value, res.data)
  })
}

const closeDialog = () => {
  visible.value = false;
};

const submitForm = async () => {
  try {
    await putObj(form.value);
    useMessage().success('策略更新成功');
    closeDialog();
  } catch (err: any) {
    useMessage().error(err.msg);
  }
};

defineExpose({
  openDialog
});
</script>
